/*
 * table_DataSection.c
 *
 *  Created on: 2012/07/03
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"

typedef struct _DATASECTION
{
	AST			astName;
	U4          size;
} DATASECTION, *PDATASECTION;

#define TableSize  (sizeof(DATASECTION ))
#define TableType  PDATASECTION
#define stTable stDataSectionManager.memoryBlocks
#define maxTable stDataSectionManager.maxRecordNum
#define  maxNumPerBlk  (stDataSectionManager.astMaxNum_Block)
static TABLEMANAGER stDataSectionManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stDataSectionManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stDataSectionManager, resetListener,  index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stDataSectionManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stDataSectionManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stDataSectionManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}
//	IDX_SYMNAME	STR_SYMNAME
static CHAR*  getSymName( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return stCoreLabelStrAccess.getStr(pTbl->astName);
}
/* set method */
static AST  setSymName( AST index, PSZ value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astName = stCoreLabelStrAccess.addStr( value );
}
//	U4_SIZE
static U4  getSize( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->size ;
}
/* set method */
static U4  setSize( AST index, U4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->size = value;
}
const DATASECTION_ACCESS stDataSectionAccess = {
		ClearTable,
		ResetTable,
		AllocTable,
		getMaxLineNum,
		{
				getSymName,
				setSymName
		},
		{
				getSize,
				setSize
		}
};
